package com.cadre.web.controller.officer;

import com.cadre.common.utils.R;
import com.cadre.system.service.DataStreamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@Api(tags = {"数据上报-数据接收"})
@RequestMapping({"/data/stream"})
@RestController
/* loaded from: DataStreamController.class */
public class DataStreamController {
    @Autowired
    DataStreamService dataStreamService;
    public static String msg;

    @PostMapping({"/createZip"})
    @ApiOperation("数据上报生成数据包")
    public void createZip(@RequestParam(value = "cadreCategory", required = false) String cadreCategory, @RequestParam(value = "ranknew", required = false) String ranknew, @RequestParam(value = "checkData", required = false) String checkData, @RequestParam(value = "rank", required = false) String rank, HttpServletResponse response) {
        Map<String, String> map = new HashMap<>();
        if (checkData != null) {
            map.put("unitid", checkData.trim());
        } else {
            map.put("unitid", "");
        }
        if (cadreCategory != null) {
            map.put("A0181", cadreCategory.trim());
        } else {
            map.put("A0181", "");
        }
        if (rank != null) {
            map.put("A0179", rank.trim());
        } else {
            map.put("A0179", "");
        }
        if (ranknew != null) {
            map.put("A0198", ranknew.trim());
        } else {
            map.put("A0198", "");
        }
        this.dataStreamService.createZip(map, response);
    }

    @PostMapping({"/outStreamList"})
    @ApiOperation("数据上报生成数据包")
    public R outStreamList(@RequestBody Map<String, String> paramData) {
        Map<String, String> map = new HashMap<>();
        if (paramData.get("checkData") != null) {
            map.put("unitid", paramData.get("checkData").trim());
        }
        if (paramData.get("cadreCategory") != null) {
            map.put("A0181", paramData.get("cadreCategory").trim());
        }
        if (paramData.get("rank") != null) {
            map.put("A0179", paramData.get("rank").trim());
        }
        if (paramData.get("ranknew") != null) {
            map.put("A0198", paramData.get("ranknew").trim());
        }
        return this.dataStreamService.outStreamList(map);
    }

    @PostMapping({"/impZip"})
    @ApiOperation("导入zip")
    @ResponseBody
    public R impZip(@RequestParam("file") MultipartFile file, HttpServletResponse response) {
        return this.dataStreamService.impZip(file);
    }

    @GetMapping({"/exportDate/{toUserId}"})
    @ApiOperation("数据导入")
    @ResponseBody
    public R exportDate(@RequestParam Map<String, Object> params, @PathVariable String toUserId) {
        if (params.get("type") == null) {
            params.put("type", 1);
        }
        if (params.get("unitid") == null) {
            params.put("unitid", 2);
        }
        if (params.get("exportType") == null) {
            params.put("exportType", 1);
        }
        this.dataStreamService.exportDate(params, toUserId);
        return R.ok();
    }
}
